﻿using MicroMVVM.Interfaces;
using System;
using Windows.UI.Xaml.Controls;

namespace MicroMVVM.Services.Any
{
    [ExportService(ServiceType.Any, typeof (IViewAware), PartCreationPolicy.Singleton)]
    public class ViewAwareService : IViewAware
    {
        private Control _current;

        /// <summary>
        /// Gets/Sets the current view.
        /// </summary>
        public Control Current
        {
            get { return _current; }
            set
            {
                _current = value;

                if (RaiseControl != null) RaiseControl.BeginInvoke(value, c => RaiseControl.EndInvoke(c), null);
            }
        }

        /// <summary>
        /// Gets the current view action.
        /// </summary>
        public Action<Control> RaiseControl { get; set; }
    }
}